class_name Hand
extends HBoxContainer

@onready var cardScene := preload ("res://scenes/card/card.tscn")

# 手牌添加
func addCard(cardSrc: CardSrc) -> void:
	var newCard := cardScene.instantiate()
	add_child(newCard)
	newCard.joinHand.connect(onJoinHand)
	newCard.cardSrc = cardSrc
	newCard.parent = self

# 返回手牌   
func onJoinHand(card: Card) -> void:
	card.reparent(self)
	# 设置回到手牌的卡牌索引
	var index := clampi(card.index, 0, get_child_count())
	# 帧尾部调用
	move_child.call_deferred(card, index)

# 弃牌
func discard(card: Card) -> void:
	card.queue_free()

# 禁用手牌
func disableHand() -> void:
	# 弃牌期间禁止卡牌的互动
	for card in get_children():
		card.disable = true
